package com.tbit.uqbike.object.pojo.vo;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.tbit.uqbike.annos.Excel;
import com.tbit.uqbike.constant.BmsConfigConstant;
import lombok.Data;

import java.util.Date;

/**
 * 云bms电池返回值实体类
 *
 * @Author:BUGTian
 * @DATE: 2022/7/19
 */
@Data
public class BmsBatteryVO {

    /**
     * 电池编号
     */
    @Excel(name = "电池编号", sort = 1)
    private String batteryNO;
    /**
     * 电池型号id
     */
    private Integer batteryModelId;
    /**
     * 电池品牌
     */
    @Excel(name = "电池品牌", sort = 2)
    private String batteryBrand;
    /**
     * 电池型号
     */
    @Excel(name = "电池型号", sort = 3)
    private String batteryModel;
    /**
     * 电池容量
     */
    @Excel(name = "电池容量", sort = 4)
    private String batteryCapacity;
    /**
     * 批次号
     */
    private Integer batch;
    /**
     * 批次名称
     */
    @Excel(name = "电池批次", sort = 10)
    private String batchName;
    /**
     * 添加时间
     */
    private Date addTime;
    /**
     * 初次使用时间
     */
    @Excel(name = "电池初次使用时间", sort = 5, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date firstTime;
    /**
     * 已使用时间
     */
    @Excel(name = "已使用时间", sort = 6)
    private String useTime;
    /**
     * 充放电次数
     */
    @Excel(name = "充放电次数", sort = 7)
    private Integer useCount;
    /**
     * 标称骑行里程(km)
     */
    @Excel(name = "标称里程(km)", sort = 8)
    private Integer maxMileage;
    /**
     * 最后骑行里程，单位米
     */
    @Excel(name = "最后实际骑行里程(km)", sort = 9)
    private Double finallyMileage;
    /**
     * 总骑行里程，单位米
     */
    @Excel(name = "总骑行里程(km)", sort = 11)
    private Double sumMileage;
    /**
     * 异常状态
     */
    @Excel(name = "异常状态", readConverterExp = "1=待定义状态1,2=待定义状态2")
    private Integer abnormalType;
    /**
     * 电池健康度
     */
    @Excel(name = "电池健康度", sort = 12)
    private Integer health;
    /**
     * 电池健康度等级
     */
    @Excel(name = "电池健康度等级", sort = 13)
    private String healthParse;
    /**
     * 电池当前所在车辆
     */
    @Excel(name = "电池当前所在车辆", sort = 14)
    private String userCode;


/*
    //当前换电时间
    private String currentChangeTime;
    //当前旧电量
//    @Excel(name = "当前旧电量", sort = 14)
    private int currentOldSoc;
    //当前新电量
//    @Excel(name = "当前新电量", sort = 14)
    private int currentNewSoc;
    //当前消耗电量
    @Excel(name = "本次换电消耗净电量", sort = 14)
    private int consumptionSoc;
    //当前骑行里程
    @Excel(name = "本次换电骑行里程", sort = 14)
    private double currentMileage;
    //上一次换点时间
    private String previousChangeTime;
    //上一次旧电量
//    @Excel(name = "上一次旧电量", sort = 14)
    private int previousOldSoc;
    //上一次新电量
//    @Excel(name = "上一次新电量", sort = 14)
    private int previousNewSoc;
    //上一次骑行里程
//    @Excel(name = "上一次骑行里程", sort = 14)
    private double previousMileage;
*/

    /**
     * 字段解析
     *
     * @param bmsConfigVO
     */
    public void fieldParse(BmsConfigVO bmsConfigVO, Date now) {
        long between = DateUtil.between(firstTime, now, DateUnit.HOUR);
        useTime = String.format("%s小时", between);
        //续航差健康度
        Integer lifePoorHealth = bmsConfigVO.getLifePoorHealth();
        //建议回收健康度
        Integer adviceRecycleHealth = bmsConfigVO.getAdviceRecycleHealth();
        //报废健康度
        Integer scrapHealth = bmsConfigVO.getScrapHealth();
        if (health == null) {
            //如果为空，默认100，防止空指针
            health = 100;
        }
        if (health > lifePoorHealth) {
            //正常
            healthParse = BmsConfigConstant.NORMAL;
        } else if (health > adviceRecycleHealth) {
            //续航差
            healthParse = BmsConfigConstant.LIFE_POOR;
        } else if (health > scrapHealth) {
            //建议回收
            healthParse = BmsConfigConstant.ADVICE_RECYCLE;
        } else {
            //报废
            healthParse = BmsConfigConstant.SCRAP;
        }
    }

/*    public  void setConsumptionSoc(){
        this.consumptionSoc = previousNewSoc - currentNewSoc;
        if (consumptionSoc < 0){
            consumptionSoc = -1;
        }
    }*/


}
